//
//  HQTabBarViewController.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/4.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQTabBarViewController.h"

@interface HQTabBarViewController ()

@end

@implementation HQTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.barTintColor = [self colorHexValue:0x2C2E44];
        
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[self colorHexValue:0xa8aab8],NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor  whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
    
    CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context,
                                   [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setShadowImage:img];
    [self.tabBar setBackgroundImage:[[UIImage alloc]init]];
    
    // 1> 首页
    _homeNav = [self addRootNav:[[HQHomeViewController alloc]init]];
    [self setBarImg:@"bm_tab_home" withItem:_homeNav withTitle:@"首页"];

    // 2> 热点
    _hotNav = [self addRootNav:[[HQHotViewController alloc]init]];
    [self setBarImg:@"bm_tab_hot" withItem:_hotNav withTitle:@"热点"];

    // 3> 记录
    _recordNav = [self addRootNav:[[HQRecordViewController alloc]init]];
    [self setBarImg:@"bm_tab_record" withItem:_recordNav withTitle:@"记录"];

    // 4> 我的
    _mineNav = [self addRootNav:[[HQMineViewController alloc]init]];
    [self setBarImg:@"bm_tab_mine" withItem:_mineNav withTitle:@"我的"];
}

-(void)addChildViewControllers{
    self.viewControllers = @[_homeNav,_hotNav,_recordNav,_mineNav];
    
//    self.viewControllers = @[_homeNav,_recordNav,_mineNav];
}

-(UINavigationController *)addRootNav:(UIViewController *)vc{
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    return nav;
}

-(void)setBarImg:(NSString *)img withItem:(UINavigationController *)nvc withTitle:(NSString *)title{
    nvc.tabBarItem.title = title;
    nvc.tabBarItem.image = [[UIImage imageNamed:img] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nvc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_sel",img]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

@end
